<template>
  <div class="container bg-white">
    <blank
      :value="showEmpty"
      :title="empty.title"
      :message="empty.message"
      :icon="empty.icon"
    >
      <template slot="button">
        <van-button
          icon="home-o"
          round
          :to="{path:'/'}"
          replace
        >返回首页</van-button>
      </template>
    </blank>
    <van-loading
      size="24px"
      vertical
      v-if="authenting"
    >正在查找分享内容...</van-loading>
  </div>
</template>

<script>
import { Tag, Col, Icon, Button, Loading } from 'vant'
import Blank from '@/components/abnor/blank'
export default {
  components: {
    Blank,
    [Tag.name]: Tag,
    [Col.name]: Col,
    [Icon.name]: Icon,
    [Button.name]: Button,
    [Loading.name]: Loading
  },
  inject: ['reload'],
  data () {
    return {
      templates: ['spread', 'goods', 'article'],
      showEmpty: false,
      authenting: true,
      empty: {
        title: '分享内容不存在',
        message: '抱歉，当前内容不存在或者已删除',
        icon: '/static/icons/blank_authent.png'
      }
    }
  },
  created () {
    this.onLoad()
  },
  methods: {
    refresh () {
      this.reload()
    },
    onLoad () {
      this.$http.global
        .parseShareData(this.$route.params)
        .then(response => {
          let data = response.data
          console.log(data)
          console.log(this.$route.params)
          if (!data) {
            this.toPush({
              path: '/'
            })
          } else {
            if (data.type === 'goods' && data.id) {
              this.toPush({
                path: '/goods/' + data.id
              })
            } else if (data.type === 'app') {
              this.toPush({
                path: '/'
              })
            } else {
              this.toPush({
                path: '/'
              })
            }
          }
        })
        .catch(function (error) {
          console.log(error)
          this.authenting = false
          this.showEmpty = true
        })
    },
    toPush (path) {
      this.$router.replace(path)
      // this.$router.go(-1)
      this.reload()
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.fullscreen {
  height: 100%;
  overflow: hidden;
  position: relative;
  background: #fff;
  .container {
    height: 100%;
  }
}
.van-loading {
  height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.van-popup {
  h1 {
    margin: 0;
    font-size: 14px;
    padding: 15px;
    border-bottom: 1px solid #f2f2f2;
  }
}
</style>
